package com.lin.utils;


import com.lin.entity.Article;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 阿林
 */
@Component
public class Commons {
    /**
     * 缩略图
     *
     * @param article
     * @return
     */
    public static String showThumb ( Article article ) {
        String thumbnail = article.getThumbnail();
        if (thumbnail != null) {
            return thumbnail;
        } else {
            return "/user/img/rand/" + article.getId() + ".png";
        }
    }

    /**
     * 格式化日期
     *
     * @param created
     * @return
     */
    public static String dateFormat ( Date created ) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(created);
        return format;
    }

    /**
     * 文章详情页映射地址
     *
     * @param articleId
     * @return
     */
    public static String permalink ( Integer articleId ) {
        return "/articleDetail/" + articleId;
    }

    /**
     * 文章摘要
     *
     * @param article
     * @param pos
     * @return
     */
    public static String intro ( Article article, Integer pos ) {
        String content = article.getContent();
        //如果文章内容长
        if (content.length() > pos) {
            //截取摘要
            return content.substring(0, pos);
        }
        //文章短不截取
        return content;
    }

    /**
     * 文章内容
     *
     * @param content
     * @return
     */
    public static String article ( String content ) {
        return content;
    }


    public static String site_url () {
        return "/";
    }

    public static String site_url ( String url ) {
        return url;
    }

}
